//
//  CYVisitorViewCotroller.swift
//  WeiBo
//
//  Created by Mr_J on 16/3/4.
//  Copyright © 2016年 mac. All rights reserved.
//

import UIKit

class CYVisitorViewCotroller: UITableViewController {

    var userLogin:Bool = CYUserAccountViewModel.sharedAccountViewModel.userLogin
    
    override func viewDidLoad() {
        if userLogin {
    
            super.viewDidLoad()
        }else {
            setupVisitorView()
        }
     
    }
    
    private func setupVisitorView() {
        view = visitorView
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "login")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", target: self, action: "login")
        
        visitorView.registerButton.addTarget(self, action: "login", forControlEvents: UIControlEvents.TouchUpInside)
        visitorView.loginButton.addTarget(self, action: "login", forControlEvents: .TouchUpInside)
    }
   @objc private func login() {
       let cc = CYOAuthViewController()
        
        presentViewController(CYNavigationController(rootViewController:cc), animated: true, completion: nil)
        
    }
    
    lazy var visitorView: CYVisitorView = {
       
        let v = CYVisitorView()
//       v.delegate = self
        
         return v
        
    }()
}

//extension CYVisitorViewCotroller:CYVisitorViewDelegate {
//    func visitorView(visitorView: CYVisitorView, loginButtonDidClick: UIButton) {
//        login()
//    }
//}